package cn.baiy;

import javax.swing.*;

//战舰类
public class BattleShip extends SeaObject {  //继承

    private int life;  //命

    public BattleShip() {
        super(66, 26, 270, 124, 20);
        life = 5;
    }

    @Override
    public void move() {
    }

    @Override
    public ImageIcon getImage() {////////////抽象方法必须重写（相当于把{}补上才能用）
        return Images.battleship;
    }

    public Bomb shootBomb() {
        return new Bomb(x, y);
    }

    public void moveLeft() {
        x -= speed; //左移动
        if (x <= 0) {
            x = 0;
        }
    }

    public void moveRight() {
        x += speed; //右移动
        if (x >= World.WIDTH - width) {
            x = World.WIDTH - width;
        }
    }

    public void addLife(int num) {
        life += num; //加命
    }

    public int getLife() {
        return life; //返回命数
    }

    public void subtractLife() {
        life--; //战舰减命
    }

}
